using Perfect.Marshal;
using System.Xml;

namespace editor
{
namespace cfg.item
{
[System.Serializable]
public  class ItemEqual : ItemBasic
 {

    public System.Collections.Generic.List<int> equalItem  = new System.Collections.Generic.List<int>();
     


    public const int TYPE_ID = 278439280;

    public override int GetTypeId() {
        return TYPE_ID;
    }


    public override void MarshalCompatible(Perfect.Marshal.Octets os) {
        os.WriteSize(12);
        os.WriteSize(Tag.INT | (1 << Tag.TAG_SHIFT));  os.WriteInt(id);  
         os.WriteSize(Tag.STRING | (2 << Tag.TAG_SHIFT));  os.WriteString(name);  
         os.WriteSize(Tag.INT | (3 << Tag.TAG_SHIFT));  os.WriteInt((int)itemType);  
         os.WriteSize(Tag.STRING | (4 << Tag.TAG_SHIFT));  os.WriteString(displayItemType);  
         os.WriteSize(Tag.STRING | (5 << Tag.TAG_SHIFT));  os.WriteString(icon);  
         os.WriteSize(Tag.INT | (6 << Tag.TAG_SHIFT));  os.WriteInt((int)quality);  
         os.WriteSize(Tag.INT | (7 << Tag.TAG_SHIFT));  os.WriteInt(prize);  
         os.WriteSize(Tag.STRING | (8 << Tag.TAG_SHIFT));  os.WriteString(introduction);  
         os.WriteSize(Tag.INT | (9 << Tag.TAG_SHIFT));  os.WriteInt(maxPile);  
         os.WriteSize(Tag.BOOL | (10 << Tag.TAG_SHIFT));  os.WriteBool(batch);  
         os.WriteSize(Tag.BOOL | (11 << Tag.TAG_SHIFT));  os.WriteBool(canSell);  
         os.WriteSize(Tag.LIST | (12 << Tag.TAG_SHIFT));  { var _oldOs = os; os = new Perfect.Marshal.Octets(); cfg.Extensions.marshal_compatible_list_int(equalItem,os);  _oldOs.WriteOctets(os); os = _oldOs;}  
         
    }

    public override void UnmarshalCompatible(Perfect.Marshal.Octets os) {
        for (int _var_num_ = os.ReadSize(); _var_num_-- > 0; ) {
            int _id_ = os.ReadSize();
            switch (_id_)
            {
            case (Tag.INT | (1 << Tag.TAG_SHIFT)):   id = os.ReadInt(); break;  
             case (Tag.STRING | (2 << Tag.TAG_SHIFT)):   name = os.ReadString(); break;  
             case (Tag.INT | (3 << Tag.TAG_SHIFT)):   itemType = (cfg.item.EItemType)(os.ReadInt()); break;  
             case (Tag.STRING | (4 << Tag.TAG_SHIFT)):   displayItemType = os.ReadString(); break;  
             case (Tag.STRING | (5 << Tag.TAG_SHIFT)):   icon = os.ReadString(); break;  
             case (Tag.INT | (6 << Tag.TAG_SHIFT)):   quality = (cfg.item.EItemColor)(os.ReadInt()); break;  
             case (Tag.INT | (7 << Tag.TAG_SHIFT)):   prize = os.ReadInt(); break;  
             case (Tag.STRING | (8 << Tag.TAG_SHIFT)):   introduction = os.ReadString(); break;  
             case (Tag.INT | (9 << Tag.TAG_SHIFT)):   maxPile = os.ReadInt(); break;  
             case (Tag.BOOL | (10 << Tag.TAG_SHIFT)):   batch = os.ReadBool(); break;  
             case (Tag.BOOL | (11 << Tag.TAG_SHIFT)):   canSell = os.ReadBool(); break;  
             case (Tag.LIST | (12 << Tag.TAG_SHIFT)):  { var _oldOs = os; os = os.ReadOctets(); equalItem = cfg.Extensions.unmarshal_compatible_list_int(os); os = _oldOs; break; }   
             
            default: Tag.SkipUnknownField(_id_, os); break;
            }
         }
    }
    public override void MarshalXml(XmlWriter ele)
    {
        ele.WriteAttributeString("type", "ItemEqual");
        ele.WriteStartElement("id"); ele.WriteAttributeString("id", "1"); ele.WriteInt(id); ele.WriteEndElement();
         ele.WriteStartElement("name"); ele.WriteAttributeString("id", "2"); ele.WriteString2(name); ele.WriteEndElement();
         ele.WriteStartElement("itemType"); ele.WriteAttributeString("id", "3"); ele.WriteEnum(itemType); ele.WriteEndElement();
         ele.WriteStartElement("displayItemType"); ele.WriteAttributeString("id", "4"); ele.WriteString2(displayItemType); ele.WriteEndElement();
         ele.WriteStartElement("icon"); ele.WriteAttributeString("id", "5"); ele.WriteString2(icon); ele.WriteEndElement();
         ele.WriteStartElement("quality"); ele.WriteAttributeString("id", "6"); ele.WriteEnum(quality); ele.WriteEndElement();
         ele.WriteStartElement("prize"); ele.WriteAttributeString("id", "7"); ele.WriteInt(prize); ele.WriteEndElement();
         ele.WriteStartElement("introduction"); ele.WriteAttributeString("id", "8"); ele.WriteString2(introduction); ele.WriteEndElement();
         ele.WriteStartElement("maxPile"); ele.WriteAttributeString("id", "9"); ele.WriteInt(maxPile); ele.WriteEndElement();
         ele.WriteStartElement("batch"); ele.WriteAttributeString("id", "10"); ele.WriteBool(batch); ele.WriteEndElement();
         ele.WriteStartElement("canSell"); ele.WriteAttributeString("id", "11"); ele.WriteBool(canSell); ele.WriteEndElement();
         ele.WriteStartElement("equalItem"); ele.WriteAttributeString("id", "12"); cfg.Extensions.xml_marshal_list_int(equalItem,ele); ele.WriteEndElement();
         
    }

    public override void UnmarshalXml(XmlElement ele)
    {
        foreach (XmlElement e in ele.GetChildren())
        {
            if (int.TryParse(ele.GetAttribute("id"), out var _id_))
            {
                switch (_id_)
                {
                case 1:  id = ele.ReadInt(); break; 
                 case 2:  name = ele.ReadString2(); break; 
                 case 3:  itemType = ele.ReadEnum<cfg.item.EItemType>(); break; 
                 case 4:  displayItemType = ele.ReadString2(); break; 
                 case 5:  icon = ele.ReadString2(); break; 
                 case 6:  quality = ele.ReadEnum<cfg.item.EItemColor>(); break; 
                 case 7:  prize = ele.ReadInt(); break; 
                 case 8:  introduction = ele.ReadString2(); break; 
                 case 9:  maxPile = ele.ReadInt(); break; 
                 case 10:  batch = ele.ReadBool(); break; 
                 case 11:  canSell = ele.ReadBool(); break; 
                 case 12:  equalItem = cfg.Extensions.xml_unmarshal_list_int(ele); break; 
                 
                default: break;
                }
            }
            else
            {
                switch (e.Name)
                {
                case "id":  id = ele.ReadInt(); break; 
                 case "name":  name = ele.ReadString2(); break; 
                 case "item_type":  itemType = ele.ReadEnum<cfg.item.EItemType>(); break; 
                 case "display_item_type":  displayItemType = ele.ReadString2(); break; 
                 case "icon":  icon = ele.ReadString2(); break; 
                 case "quality":  quality = ele.ReadEnum<cfg.item.EItemColor>(); break; 
                 case "prize":  prize = ele.ReadInt(); break; 
                 case "introduction":  introduction = ele.ReadString2(); break; 
                 case "max_pile":  maxPile = ele.ReadInt(); break; 
                 case "batch":  batch = ele.ReadBool(); break; 
                 case "can_sell":  canSell = ele.ReadBool(); break; 
                 case "equal_item":  equalItem = cfg.Extensions.xml_unmarshal_list_int(ele); break; 
                 
                default: break;
                }
            }
        }
    }
}
}
}
